package com.hui.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class DBUtils {

    private static final String MYBATIS_CONFIG_PATH= "mybatis-config.xml";

    private static SqlSessionFactory sqlSessionFactory;


    static {
        try {
            InputStream is = Resources.getResourceAsStream(MYBATIS_CONFIG_PATH);
            sqlSessionFactory=new SqlSessionFactoryBuilder().build(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public  static SqlSession getSqlSession(){
        return sqlSessionFactory.openSession();
    }


}
